﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace game
{
    public class WeaponState
    {

        private Scene scene;
        private Ship playerShip;

        private Texture2D rocketImg;
        private Texture2D blasterImg;
        private Texture2D plasmaImg;
        private Texture2D shieldImg;
        private Texture2D shieldBarImg;

        private SpriteBatch spriteBatch;

        private int scrWidth;
        private int scrHeight;

        public WeaponState(Scene scene, Ship playerShip)
        {
            this.scene = scene;
            this.playerShip = playerShip;

            this.spriteBatch = ShooterGame.Instance.SpriteBatch;

            this.rocketImg = ShooterGame.Instance.Content.Load<Texture2D>("Textures\\hud\\rocket");
            this.blasterImg = ShooterGame.Instance.Content.Load<Texture2D>("Textures\\hud\\blaster");
            this.plasmaImg = ShooterGame.Instance.Content.Load<Texture2D>("Textures\\hud\\plasma");
            this.shieldImg = ShooterGame.Instance.Content.Load<Texture2D>("Textures\\hud\\shield");
            this.shieldBarImg = ShooterGame.Instance.Content.Load<Texture2D>("Textures\\hud\\shield-bar");

            this.scrWidth = ShooterGame.Instance.GraphicsDevice.PresentationParameters.BackBufferWidth;
            this.scrHeight = ShooterGame.Instance.GraphicsDevice.PresentationParameters.BackBufferHeight;
        }

        public void Update(GameTime gameTime)
        {
        }

        public void Draw(GameTime gameTime)
        {
            Rectangle destRect = new Rectangle();
            destRect.Width = 128;
            destRect.Height = 64;


            destRect.X = scrWidth - destRect.Width - 65;
            destRect.Y = scrHeight - destRect.Height - 100;

            spriteBatch.Begin(SpriteBlendMode.Additive);

            spriteBatch.Draw(rocketImg, destRect, Color.White);

            spriteBatch.DrawString(Text2D.SpriteFont,
                playerShip.RocketLauncher.ProjectileQuantity.ToString(),
                new Vector2(scrWidth - 60, scrHeight - 146),
                Color.White, 0, new Vector2(0,0), 1.8f, SpriteEffects.None, 1);



            destRect.Y = scrHeight - destRect.Height - 50;

            Weapon weapon = playerShip.Weapons[playerShip.ActiveWeaponIndex];
            if (weapon is Blaster)
                spriteBatch.Draw(blasterImg, destRect, Color.White);
            else if(weapon is PlasmaGun)
                spriteBatch.Draw(plasmaImg, destRect, Color.White);

            spriteBatch.DrawString(Text2D.SpriteFont,
                weapon.ProjectileQuantity.ToString(),
                new Vector2(scrWidth - 60, scrHeight - 96),
                Color.White, 0, new Vector2(0, 0), 1.8f, SpriteEffects.None, 1);


            destRect.X += 5;
            destRect.Y = scrHeight - destRect.Height - 150;
            destRect.Width = 48;
            destRect.Height = 48;
            spriteBatch.Draw(shieldImg, destRect, Color.White);

            float barState;
            if (playerShip.Shield.On)
                barState = playerShip.Shield.LifetimeLevel;
            else
                barState = playerShip.Shield.LoadLevel;

            destRect.X += 62;
            destRect.Y += 8;
            destRect.Width = (int)(108 * barState);
            destRect.Height = 32;

            Rectangle srcRect = new Rectangle(10, 0, (int)(108 * barState), 32);
            spriteBatch.Draw(shieldBarImg, destRect, srcRect, Color.White);

            spriteBatch.End();
        }
    }
}
